#
# @lc app=leetcode.cn id=367 lang=python3
#
# [367] 有效的完全平方数
#

# @lc code=start
class Solution:
    def isPerfectSquare(self, num: int) -> bool:
        left, right = 2, num//2

        if num >= 4:
            while left <= right:
                mid = left + (right - left) // 2
                if mid*mid < num:
                    left = mid + 1
                elif mid*mid > num:
                    right = mid - 1
                else:
                    return True
        elif num == 1:
            return True
        return False
# @lc code=end

